package com.bocai.kelalacar.ui.car.main.act;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelalacar.App;
import com.bocai.kelalacar.R;
import com.bocai.kelalacar.base.BaseActivity;
import com.bocai.kelalacar.bean.ModifyAddressBean;
import com.bocai.kelalacar.ui.car.main.contract.ModifyAddressContract;
import com.bocai.kelalacar.ui.car.main.module.MessageModule;
import com.bocai.kelalacar.ui.car.main.module.ModifyAddressModule;
import com.bocai.kelalacar.ui.car.main.presenter.ModifyAddressPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by yuanfei on 2017/8/25.
 */

public class ModifyAddressActivity extends BaseActivity implements ModifyAddressContract.view {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.ll_delete)
    LinearLayout llDelete;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_start_address)
    TextView tvStartAddress;
    @BindView(R.id.tv_end_address)
    TextView tvEndAddress;
    @BindView(R.id.tv_start_address1)
    TextView tvStartAddress1;
    @BindView(R.id.tv_end_address1)
    TextView tvEndAddress1;
    @BindView(R.id.btn_disagree)
    Button btnDisagree;
    @BindView(R.id.btn_agree)
    Button btnAgree;
    @Inject
    ModifyAddressPresenter presenter;
    private String orderId;
    private int index = 0;

    @Override
    public int getLayoutId() {
        return R.layout.act_modify_address;
    }

    @Override
    public void initPresenter() {
        App.get(this).getAppComponent().addSub(new ModifyAddressModule(this)).inject(this);
    }

    @Override
    public void initView() {
        initToolbar("修改线路");
        initBack(imgBack,llBack);
        orderId = getIntent().getStringExtra("orderId");
        index = getIntent().getIntExtra("index",0);
        if (index == 1){
            btnAgree.setVisibility(View.GONE);
            btnDisagree.setVisibility(View.GONE);
        }
        presenter.changeAddress(orderId);
    }
    @OnClick({R.id.btn_disagree,R.id.btn_agree})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_disagree:
                presenter.disAgreeChange(orderId);
                break;
            case R.id.btn_agree:
                presenter.agreeChange(orderId);
                break;
        }
    }
    @Override
    public void showLoading(String title) {
        startProgressDialog(title);
    }

    @Override
    public void stopLoading() {
        stopProgressDialog();
    }

    @Override
    public void showErrorTip(String msg) {
        showShortToast(msg);
    }

    @Override
    public void getChangeAddress(ModifyAddressBean bean) {
        tvStartAddress.setText(bean.getOldOriginAddress());
        tvEndAddress.setText(bean.getOldArriveAddress());
        tvStartAddress1.setText(bean.getNewOriginAddress());
        tvEndAddress1.setText(bean.getNewArriveAddress());
    }

    @Override
    public void disAgreeChange() {
        showErrorTip("不同意线路修改");
        setResult(123);
        finish();
    }

    @Override
    public void agreeChange() {
        showErrorTip("同意线路修改");
        setResult(123);
        finish();
    }
}
